package com.wing.robot.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.robot.dao.RobotAreaDao;
import com.wing.robot.model.entity.RobotArea;
import com.wing.robot.model.request.RobotAreaForm;
import com.wing.robot.model.response.RobotAreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 机器人调度区域-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class RobotAreaServiceImpl extends ServiceImpl<RobotAreaDao, RobotArea> implements RobotAreaService {

    @Override
    public int add(RobotAreaForm robotAreaForm) {

        //校验

        RobotArea robotArea =new RobotArea();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(RobotArea.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(robotAreaForm, robotArea, copyOptions);

        return baseMapper.insert(robotArea);
    }

    @Override
    public List<RobotAreaVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<RobotAreaVO> pageList4app(Page page, Map<String, Object> params) {
        List<RobotAreaVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public RobotAreaVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public int enable(Long id) {
        RobotAreaVO robotAreaVO = baseMapper.get4appById(id);
        if (robotAreaVO!=null){
            RobotArea robotArea = new RobotArea();
            robotArea.setId(id);
            robotArea.setIsDeleted(true);
            int updateCount =baseMapper.updateById(robotArea);
            return updateCount;
        }
        return 0;
    }

    @Override
    public int disable(Long id) {
        RobotAreaVO robotAreaVO = baseMapper.get4appById(id);
        if (robotAreaVO!=null){
            RobotArea robotArea = new RobotArea();
            robotArea.setId(id);
            robotArea.setIsDeleted(false);
            int updateCount =baseMapper.updateById(robotArea);
            return updateCount;
        }
        return 0;
    }
}
